<template>
  <div class="download-tips">下载中......  如未开始下载请→ → <el-button type="text" size="medium" @click="downloadFile">点击此处</el-button> ← ←</div>
</template>

<script>
import RuleChainApi from '@/api/ruleChain'
export default {
  name: 'download',
  data() {
    return {}
  },
  mounted() {
    // window.location.href = this.link
    this.downloadFile()
  },
  computed: {
    link() {
      return `${process.env.VUE_APP_AJAX_BASE_URL}/design/business/v1/product/file/download/productFile/${this.$route.params.id}`
    }
  },
  methods: {
    async downloadFile() {
      const res = await RuleChainApi.downloadRuleChain(this.$route.params.id)
      const download = res.headers['content-disposition'].split('fileName="')[1].slice(0, -1)
      const blob = new Blob([res.data])
      const elink = document.createElement('a')
      elink.download = download
      elink.style.display = 'none'
      elink.href = URL.createObjectURL(blob)
      document.body.appendChild(elink)
      elink.click()
      URL.revokeObjectURL(elink.href)
      document.body.removeChild(elink)
    }
  }
}
</script>
<style lang="scss" scoped>
.download-tips{
  text-align: center;
  margin-top: 20vh;
  a{
    color: red;
    text-decoration: underline;
  }
}
</style>
